var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2AudioManager = require("AudioManager");
var $2BulletMgr = require("BulletMgr");
var $2ZombieMgr = require("ZombieMgr");
var $2SceneStage = require("SceneStage");
var $2KDefine = require("KDefine");
var $2MyUtils = require("MyUtils");
var $2BulletBase = require("BulletBase");
var $2PlantBase = require("PlantBase");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_Plant3 = /* */function (_h$default2) {
  babel_inherits(p, _h$default2);
  var _super66 = babel_createSuper(p);
  function p() {
    babel_classCallCheck(this, p);
    return _super66.apply(this, arguments);
  }
  babel_createClass(p, [{
    key: "shoot",
    value: function shoot() {
      var _this144 = this;
      var e = this;
      if (0 == this.remainCD) {
        var _t43 = this.dragon.setAnimation(0, "dazhao", true);
        var _a28 = 0;
        this.dragon.setCompleteListener(function () {
          if (++_a28 == _this144.skillNums) {
            e.setState($2KDefine.State.wait);
            _this144.attackTimes += _this144.attackCD;
            _this144.remainCD = _this144.skillCD;
          }
        });
        this.dragon.setTrackEventListener(_t43, function (e, t) {
          "dazhao" == t.data.name && _this144.attack(null, true);
        });
      } else {
        this.dragon.setCompleteListener(function () {
          e.setState($2KDefine.State.wait);
        });
        var _t44 = this.getZombie();
        if (null == _t44) {
          return void e.setState($2KDefine.State.wait);
        }
        this.attackTimes += this.attackCD;
        var _a29 = this.dragon.setAnimation(0, "gongji", false);
        this.dragon.setTrackEventListener(_a29, function (e, a) {
          "gongji" == a.data.name && _this144.attack(_t44);
        });
      }
    }
  }, {
    key: "attack",
    value: function attack(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      var a;
      var n;
      var o = new cc.Vec2(this.node.getPosition().x + this.shootPo.x, this.node.getPosition().y + this.shootPo.y);
      if (t) {
        a = $2BulletMgr.default.instance().getItem(this.skillbullet, this.damage * this.skillDamage, this.hitSound, this.hitSoundVolume).node;
        $2AudioManager.default.instance.playEffect(this.skillSound, this.skillSoundVolume);
      } else {
        a = $2BulletMgr.default.instance().getItem(this.bulletId, this.damage * this.simpleDamage, this.hitSound, this.hitSoundVolume).node;
        $2AudioManager.default.instance.playEffect(this.shootSound, this.shootSoundVolume);
      }
      a.parent = $2SceneStage.default.instance.groudNode;
      a.setPosition(o);
      a.zIndex = $2KDefine.ZIndex.bullet;
      e || (e = this.getZombie());
      if (null == e) {
        return;
      }
      n = o.y > e.y ? o.y : e.y;
      var h = new cc.Vec2(o.x + (e.x - o.x) / 4, n + 200);
      var u = Math.atan2(h.y - o.y, h.x - o.x) * (180 / Math.PI);
      var g = Math.atan2(e.y - h.y, e.x - h.x) * (180 / Math.PI);
      if (o.x >= h.x) {
        u = (u + 360) % 360;
        g = (g + 360) % 360;
      }
      a.angle = u;
      var _p = .6 * ($2MyUtils.MyUtils.getDis(o.x, o.y, h.x, h.y) + $2MyUtils.MyUtils.getDis(h.x, h.y, e.x, e.y));
      a.opacity = 255;
      cc.tween(a).parallel(cc.tween(a).bezierTo((_p + 200) / (1300 * this.attackSpeed), o, h, e), cc.tween(a).to((_p + 200) / (1300 * this.attackSpeed), {
        angle: g
      })).call(function () {
        $2BulletMgr.default.instance().removeBullet(a.getComponent($2BulletBase.default));
      }).start();
    }
  }, {
    key: "getZombie",
    value: function getZombie() {
      var _this145 = this;
      var e = 99999;
      var t = null;
      for (var _a30 = 0; _a30 < $2ZombieMgr.default.instance().zombieInRow.length; _a30++) {
        $2ZombieMgr.default.instance().zombieInRow[_a30].size <= 0 || $2ZombieMgr.default.instance().zombieInRow[_a30].forEach(function (a) {
          var n = $2MyUtils.MyUtils.getDis(_this145.node.x, _this145.node.y, a.node.x, a.node.y);
          if (n < e) {
            e = n;
            t = a.node;
          }
        });
      }
      if (null == t) {
        return null;
      } else {
        return t.getPosition();
      }
    }
  }, {
    key: "checkTarget",
    value: function checkTarget() {
      return 0 != $2ZombieMgr.default.instance().zombieNums;
    }
  }]);
  return p;
}($2PlantBase.default);
def_Plant3 = cc__decorate([ccp_ccclass], def_Plant3);
exports.default = def_Plant3;